<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="no.ntnu.tdt4237.*" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <tags:header title=" - Password Reset"></tags:header>
<!--    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>PASSWORD RESET</title>
    </head>-->
<%
    boolean reset = request.getParameter("Reset") != null;
%>
    <body>

        Please insert your registered e-mail address below.<br /><br />
        <form method="post" action="resetpassword.jsp">
            <input type="text" name="user_email"></input>
            <input type="submit" name="Reset" value="Reset"></input>
        </form>


        <%
        if (reset) {
            String email = request.getParameter("user_email");

            if (!email.equals("")) {
                User u = Database.getUserByEmail(email);
                if (u != null) {
                    MailSender.sendNewPassword(u.getEmail());
                }
          
            }
        %>
        <br />
        <tags:message message="Your password has been reset. Check your e-mail."></tags:message>
        <a href="login.jsp">Return to login</a>
        <%
        }
            //String email = "EJNRGEJG";
     
            // out.println("user.toString(): "+u.toString()+"\n");
          //  if (MailSender.sendNewPassword(email)) {
        %>   
<!--        Your password has been reset. Check your e-mail.-->
        <%   //     }



            //String redirectURL = "https://tdt4237m11.idi.ntnu.no:8457/";
            //response.sendRedirect(redirectURL);
        %>

    </body>
</html>